module.exports = class extends think.cmswing.rest {
	
   /**
   * 获取充值信息
   * /api/recharge  获取全部充值
   * /api/recharge /1 获取代理id为1的栏目信息
   * @returns {Promise.<*>}
   */
	
  async getAction() {
   const cmd = this.get('cmd') || '';
   const type = this.get('type') || '';
   const uid = this.get('uid') || '';
   
   
   let map;
   if (type == 'card') { // 获取所有充房卡记录；
	 
     map = {
      'a.status': 4,
      'a.pay_status':1,
      'a.user_id':uid,
      'c.goods_no':['like', '%' + type + '%']
     };
   } else if (type == 'coin') { // 获取所有充房卡记录；
	   map = {
		'a.status': 4,
	    'a.pay_status':1,
		'a.user_id':uid,
		'c.goods_no':['like', '%' + type + '%']
	 };
   }else {
	   map = {
				'a.status': 4,
			    'a.pay_status':1,
				'a.user_id':uid
	 };
   }

   
   const orderList = await this.model('order').alias('a').join(
		      {
		        table: 'order_goods',
		        join: 'left', // join 方式，有 left, right, inner 3 种方式
		        as: 'c', // 表别名
		        on: ['c.order_id', 'a.id'] // ON 条件
		      }
		    ).where(map)
		      .field('a.id,a.order_no,a.order_amount as amount,a.binding as agent_id,a.pay_status as status,a.pay_time as payment_time,c.goods_no as type')
		      .order('a.pay_time DESC')
		      .select();
   
   console.log('orderList---------:'+JSON.stringify(orderList));
   
   for (const val of orderList) {
	   val.payment_time =  times(val.payment_time);
	   const goods = val.type.split('_');
	   val.type = goods[0];
	   val.amount = formatCurrency(val.amount);
   }
   
   return this.success(orderList);
   
  }
  
  async postAction() {
	const data = this.post();
	console.log('shop post action-data--------:'+JSON.stringify(data));
    return this.success({name:'post成功！'});
  }
  //数据状态0禁用，1启用，-1删除
};
